Imports Microsoft.Win32 'Importing the Windows Subsystem to get registry access
Imports System.IO 'Encryption,
Imports System.Text 'Encryption,
Imports System.Security.Cryptography 'Encryption!
Imports board = HardwareMotherboardID.nsMotherBoardID.MotherBoardID 'Allows for checking of Motherboard ID number. It never changes, so it's a good way of seeing if registry entries were copied to another computer
'^ If you're getting an error in the above line, re-refrence "HardwareMotherboardID.dll" (in the bin directory).

Public Class Form1
    Inherits System.Windows.Forms.Form
    'Copyright notice:  
    '############################################
    '# Copyright (c) 2005 - 2006 Tyler Menezes. #
    '#  This copyright notice must remain here! #
    '#  You may NOT claim this program as your  #
    '#   own, however no credit is nessissary.  #
    '# If you use this program, it is requested #
    '#  that you email me at tyler@tylerm.info  #
    '# and tell me how you're using it. However #
    '#    it's not required. Just requested.    #
    '#                                          #
    '#  This article available at Code Project! #
    '#            www.CodeProject.com           #
    '############################################

    'Notes:
    '-I was going to allow the use of a time server but it took much too long to ask a time server every time the program was started.
    '   I did however create methods to see if the time has expired before and to see if the time period left was bigger then the trial period.

#Region "Required Modification"
#Region "Code"

    Public Sub LoadProgramUnreg(ByVal DaysUsed As String) 'Code to use when the user continues to the program unregistered. Passes "DaysUsed" so you can use it in your code. You can also use the global variable "TrialPeriod" to display the number of days in the trial period.
        MsgBox("Were this not a demonstration, you'd have been redirected to the program by now. This program could have limited features, as you are unregistered (you're on day " & DaysUsed & " of your " & TrialPeriod & " day trial).", MsgBoxStyle.Information, "Demonstration Only!")
        Application.Exit()
    End Sub


    Public Sub LoadProgramReg(ByVal UserName As String, ByVal SerialNumber As String) 'Code to use when the user continues to the program registered. Passes "UserName" and "SerialNumber" so you can use them in your code.
        SerialNumber = SerialNumber.Insert(4, "-")
        SerialNumber = SerialNumber.Insert(8, "-")
        SerialNumber = SerialNumber.Insert(12, "-") 'Add dashes to make it look cool
        MsgBox("Were this not a demonstration, you'd have been redirected to the program by now. This program could have all features, because you are registered (your username is " & UserName & " and your serial number is " & SerialNumber & ").", MsgBoxStyle.Information, "Demonstration Only!")
        Application.Exit()
    End Sub
#End Region
#Region "Variables"
    Public TrialPeriod As Integer = 30 'Days in the trial. Thirty is usally the average, but pick what you think is right for your program.
    Public BuyNowURL As String = "http://www.programsandwebsites.com" ' The URL of the purchase page. Must begin with "http://"!
    Public RegSubKeyName As String = "HardToGuessNameHere1" 'The name for the sub-key to store registry info. It is more secure if you make this hard to guess. You can create multiple levels by using \\ (i.e. PAW\\Blah\\Yada\\Yada)
    Private key As New Encryption.Data("RandomPassword") 'If encryption is set, choose a password to encrypt with.
#End Region
#Region "Options"
    Public SilentStart As Boolean = False 'Change to True if you don't want the registration screen to show unless the trial is over.
    Public SupportMe As Boolean = True 'Change to False if you don't want to give me credit by showing the small about button. It's not required to give me credit, just appriciated.
    Public CreateKeys As Boolean = True 'Change to False if you're going to create the registry keys for start date during setup. The program will disable access if they aren't there, as opposed to creating them.
    Public EncryptKeys As Boolean = True 'Encrypt the keys so they can't be changed. Most secure when combined with the above option, but you'll have to configure setup to encrypt them! See encryption key in Variables.
#End Region
#Region "Optional Modification"
    'The following will need to be customized if...

    'you move the progress bar:
    Public ProgressBarStartingX As Integer = 8 'Customize the progress bar's left-most "x" coordinate
    Public ProgressBarStartingY As Integer = 120 'Customize the progress bar's top-most "y" coordinate
    'you resize the progress bar:
    Public ProgressBarWidth As Integer = 624 'Customize the progress bar's total width
    Public ProgressBarHeight As Integer = 32 'Customize the progress bar's total height

#End Region
#End Region


#Region "No Modifications Nessissary"
    '##########################################################################################
    '# No modifications nessissary below this point. You can modify it if you want to though. #
    '#                 I'm just not responsible for damage to your system! :P                 #
    '##########################################################################################
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TrialPeriodDisplay As System.Windows.Forms.PictureBox
    Friend WithEvents TrialText As System.Windows.Forms.Label
    Friend WithEvents UsedTrialBar As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents unregbutton As System.Windows.Forms.Button
    Friend WithEvents unlockbutton As System.Windows.Forms.Button
    Friend WithEvents buybutton As System.Windows.Forms.Button
    Friend WithEvents exitbutton As System.Windows.Forms.Button
    Friend WithEvents About As System.Windows.Forms.PictureBox
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.TrialPeriodDisplay = New System.Windows.Forms.PictureBox
        Me.PictureBox2 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.TrialText = New System.Windows.Forms.Label
        Me.UsedTrialBar = New System.Windows.Forms.PictureBox
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.unregbutton = New System.Windows.Forms.Button
        Me.unlockbutton = New System.Windows.Forms.Button
        Me.buybutton = New System.Windows.Forms.Button
        Me.exitbutton = New System.Windows.Forms.Button
        Me.About = New System.Windows.Forms.PictureBox
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        CType(Me.TrialPeriodDisplay, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.UsedTrialBar, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.About, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'TrialPeriodDisplay
        '
        Me.TrialPeriodDisplay.BackColor = System.Drawing.Color.Transparent
        Me.TrialPeriodDisplay.Image = CType(resources.GetObject("TrialPeriodDisplay.Image"), System.Drawing.Image)
        Me.TrialPeriodDisplay.Location = New System.Drawing.Point(8, 120)
        Me.TrialPeriodDisplay.Name = "TrialPeriodDisplay"
        Me.TrialPeriodDisplay.Size = New System.Drawing.Size(624, 32)
        Me.TrialPeriodDisplay.TabIndex = 0
        Me.TrialPeriodDisplay.TabStop = False
        '
        'PictureBox2
        '
        Me.PictureBox2.BackColor = System.Drawing.Color.Transparent
        Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image)
        Me.PictureBox2.Location = New System.Drawing.Point(120, 24)
        Me.PictureBox2.Name = "PictureBox2"
        Me.PictureBox2.Size = New System.Drawing.Size(488, 40)
        Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox2.TabIndex = 1
        Me.PictureBox2.TabStop = False
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.Color.Black
        Me.Label1.Location = New System.Drawing.Point(120, 64)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(480, 16)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "In order to continue to use it beyond the alloted trial period you must register." & _
            ""
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TrialText
        '
        Me.TrialText.BackColor = System.Drawing.Color.Transparent
        Me.TrialText.ForeColor = System.Drawing.Color.Black
        Me.TrialText.Location = New System.Drawing.Point(8, 152)
        Me.TrialText.Name = "TrialText"
        Me.TrialText.Size = New System.Drawing.Size(624, 16)
        Me.TrialText.TabIndex = 3
        Me.TrialText.Text = "You have 30 days remaining in your free trial period."
        Me.TrialText.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'UsedTrialBar
        '
        Me.UsedTrialBar.BackColor = System.Drawing.Color.Transparent
        Me.UsedTrialBar.Image = CType(resources.GetObject("UsedTrialBar.Image"), System.Drawing.Image)
        Me.UsedTrialBar.Location = New System.Drawing.Point(312, 120)
        Me.UsedTrialBar.Name = "UsedTrialBar"
        Me.UsedTrialBar.Size = New System.Drawing.Size(320, 32)
        Me.UsedTrialBar.TabIndex = 4
        Me.UsedTrialBar.TabStop = False
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.Color.Transparent
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(8, 8)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(96, 96)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox1.TabIndex = 5
        Me.PictureBox1.TabStop = False
        '
        'unregbutton
        '
        Me.unregbutton.BackColor = System.Drawing.Color.Transparent
        Me.unregbutton.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.unregbutton.ForeColor = System.Drawing.Color.Black
        Me.unregbutton.Image = CType(resources.GetObject("unregbutton.Image"), System.Drawing.Image)
        Me.unregbutton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.unregbutton.Location = New System.Drawing.Point(8, 176)
        Me.unregbutton.Name = "unregbutton"
        Me.unregbutton.Size = New System.Drawing.Size(168, 56)
        Me.unregbutton.TabIndex = 6
        Me.unregbutton.Text = "Continue Unregistered"
        Me.unregbutton.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.unregbutton.UseVisualStyleBackColor = False
        Me.unregbutton.Visible = False
        '
        'unlockbutton
        '
        Me.unlockbutton.BackColor = System.Drawing.Color.Transparent
        Me.unlockbutton.Cursor = System.Windows.Forms.Cursors.Hand
        Me.unlockbutton.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.unlockbutton.ForeColor = System.Drawing.Color.Black
        Me.unlockbutton.Image = CType(resources.GetObject("unlockbutton.Image"), System.Drawing.Image)
        Me.unlockbutton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.unlockbutton.Location = New System.Drawing.Point(386, 176)
        Me.unlockbutton.Name = "unlockbutton"
        Me.unlockbutton.Size = New System.Drawing.Size(184, 56)
        Me.unlockbutton.TabIndex = 7
        Me.unlockbutton.Text = "Unlock Program"
        Me.unlockbutton.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.unlockbutton.UseVisualStyleBackColor = False
        '
        'buybutton
        '
        Me.buybutton.BackColor = System.Drawing.Color.Transparent
        Me.buybutton.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.buybutton.ForeColor = System.Drawing.Color.Black
        Me.buybutton.Image = CType(resources.GetObject("buybutton.Image"), System.Drawing.Image)
        Me.buybutton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.buybutton.Location = New System.Drawing.Point(21, 176)
        Me.buybutton.Name = "buybutton"
        Me.buybutton.Size = New System.Drawing.Size(184, 56)
        Me.buybutton.TabIndex = 8
        Me.buybutton.Text = "Purchase Unlock Key"
        Me.buybutton.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.buybutton.UseVisualStyleBackColor = False
        Me.buybutton.Visible = False
        '
        'exitbutton
        '
        Me.exitbutton.BackColor = System.Drawing.Color.Transparent
        Me.exitbutton.Cursor = System.Windows.Forms.Cursors.Hand
        Me.exitbutton.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.exitbutton.ForeColor = System.Drawing.Color.Black
        Me.exitbutton.Image = CType(resources.GetObject("exitbutton.Image"), System.Drawing.Image)
        Me.exitbutton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.exitbutton.Location = New System.Drawing.Point(576, 176)
        Me.exitbutton.Name = "exitbutton"
        Me.exitbutton.Size = New System.Drawing.Size(60, 56)
        Me.exitbutton.TabIndex = 9
        Me.exitbutton.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.exitbutton.UseVisualStyleBackColor = False
        '
        'About
        '
        Me.About.BackColor = System.Drawing.Color.Transparent
        Me.About.Image = CType(resources.GetObject("About.Image"), System.Drawing.Image)
        Me.About.Location = New System.Drawing.Point(624, 0)
        Me.About.Name = "About"
        Me.About.Size = New System.Drawing.Size(16, 16)
        Me.About.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.About.TabIndex = 10
        Me.About.TabStop = False
        Me.About.Visible = False
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(640, 240)
        Me.ControlBox = False
        Me.Controls.Add(Me.About)
        Me.Controls.Add(Me.exitbutton)
        Me.Controls.Add(Me.buybutton)
        Me.Controls.Add(Me.unlockbutton)
        Me.Controls.Add(Me.unregbutton)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.UsedTrialBar)
        Me.Controls.Add(Me.TrialText)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.PictureBox2)
        Me.Controls.Add(Me.TrialPeriodDisplay)
        Me.ForeColor = System.Drawing.Color.Black
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Registration"
        CType(Me.TrialPeriodDisplay, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.UsedTrialBar, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.About, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
#Region "Methods"
    Public hash As New Encryption.Hash(Encryption.Hash.Provider.SHA512)
    Structure CurrentDate
        Dim Day As String
        Dim Month As String
        Dim Year As String
    End Structure
    Public Sub FillBar(ByVal DaysUsed As Integer, ByVal TotalDays As Integer) 'Method to fill the progress bar (nothing here to modify really...
        'Check if the author made the mistake of setting the trial period days to less than 0
        If TotalDays < 0 Then
            MsgBox("An error has occurred!" & Chr(13) & Chr(13) & "The author has alloted you a trial period less than zero days, which is impossible. Please contact the author and tell him/her of this error.")
            Application.Exit()
        End If
        'Check if the trial is expired
        If DaysUsed > TotalDays Then
            TrialText.Text = "Your trial has expired!"
            UsedTrialBar.Size = New System.Drawing.Size(ProgressBarWidth, ProgressBarHeight)
            UsedTrialBar.Location = New System.Drawing.Point(ProgressBarStartingX, ProgressBarStartingY)
            TrialPeriodDisplay.Visible = False
            Exit Sub
        ElseIf DaysUsed = TotalDays Then
            TrialText.Text = "Your trial has expired!"
            UsedTrialBar.Size = New System.Drawing.Size(ProgressBarWidth, ProgressBarHeight)
            UsedTrialBar.Location = New System.Drawing.Point(ProgressBarStartingX, ProgressBarStartingY)
            TrialPeriodDisplay.Visible = False
            Exit Sub
        End If
        'Calculate the percentage used; store it as PercentDone
        Dim PercentDone = DaysUsed / TotalDays
        'Draw the bar
        TrialPeriodDisplay.Size = New System.Drawing.Size((ProgressBarWidth - ((ProgressBarWidth / TotalDays) * DaysUsed)), ProgressBarHeight)
        TrialText.Text = "You have " & (TotalDays - DaysUsed) & " days remaining in your free trial period."
        'Now that that's out of the way...
        'More code!
        'This time fill the used bar... and move it to the right place
        UsedTrialBar.Size = New System.Drawing.Size(((ProgressBarWidth / TotalDays) * DaysUsed), ProgressBarHeight)
        UsedTrialBar.Location = New System.Drawing.Point((ProgressBarStartingX + (ProgressBarWidth - ((ProgressBarWidth / TotalDays) * DaysUsed))), ProgressBarStartingY)

    End Sub
    Public Sub CreateRegKeys()
        Try
            Dim Current As CurrentDate
            Current.Day = DateTime.Now.Day
            Current.Month = DateTime.Now.Month
            Current.Year = DateTime.Now.Year
            If EncryptKeys = True Then
                Current.Day = Encrypt(Current.Day)
                Current.Month = Encrypt(Current.Month)
                Current.Year = Encrypt(Current.Year)
            End If
            Dim oReg As RegistryKey
            oReg = Registry.LocalMachine.OpenSubKey("Software", True)
            oReg = oReg.CreateSubKey(RegSubKeyName)
            oReg.SetValue("UserSettings", Current.Day)
            oReg.SetValue("operatingsystem", Current.Month)
            oReg.SetValue("GUID", Current.Year)
            oReg.Close()
        Catch
        End Try
    End Sub
    Public Function DiffDate(ByVal OrigDay As String, ByVal OrigMonth As String, ByVal OrigYear As String)
        'Try
        '    Dim D1 = OrigMonth & "/" & OrigDay & "/" & OrigYear
        '    Return DateDiff(DateInterval.Day, D1, DateTime.Now)
        'Catch
        Return 0
        'End Try
    End Function
    Function Encrypt(ByVal text As String)
        Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)
        Dim encryptedData As Encryption.Data
        encryptedData = sym.Encrypt(New Encryption.Data(text), key)
        Return encryptedData.ToHex
    End Function
    Function Decrypt(ByVal hexstream As String)
        Try
            Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)
            Dim encryptedData As New Encryption.Data
            encryptedData.Hex = hexstream
            Dim decryptedData As Encryption.Data
            decryptedData = sym.Decrypt(encryptedData, key)
            Return decryptedData.ToString
        Catch
        End Try
    End Function
    Function DecryptU(ByVal hexstream As String)
        Try
            Dim register As New register
            Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)
            Dim encryptedData As New Encryption.Data
            encryptedData.Hex = hexstream
            Dim decryptedData As Encryption.Data
            decryptedData = sym.Decrypt(encryptedData, register.skey)
            Return decryptedData.ToString
        Catch
        End Try
    End Function
    Function EncryptU(ByVal text As String)
        Dim register As New register
        Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)
        Dim encryptedData As Encryption.Data
        encryptedData = sym.Encrypt(New Encryption.Data(text), register.skey)
        Return encryptedData.ToHex
    End Function
#End Region
#Region "Object Subs"
    Public InTrial As Boolean = True
    Public FullVersion As Boolean = False
    Public UsedTrialDays As String = ""
    Public RN = ""
    Public RC = ""
    'Load
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oReg As RegistryKey
        oReg = Registry.LocalMachine.OpenSubKey("Software", True)
        oReg = oReg.CreateSubKey(RegSubKeyName)
        oReg = Registry.LocalMachine.OpenSubKey("Software\\" & RegSubKeyName)
        Dim OldDay As String = oReg.GetValue("UserSettings", "").ToString
        Dim OldMonth As String = oReg.GetValue("operatingsystem", "").ToString
        Dim OldYear As String = oReg.GetValue("GUID", "").ToString
        Dim RegName As String = oReg.GetValue("USERID", "").ToString
        Dim RegCode As String = oReg.GetValue("LOCALPATH", "").ToString
        Dim CompID As String = oReg.GetValue("CompID", "").ToString
        Dim TrialDone As String = oReg.GetValue("Enable", "").ToString
        oReg.Close()

        'If the keys should automatically be created, then create them.
        Select Case CreateKeys
            Case True
                If OldDay = "" Then
                    CreateRegKeys()
                End If
            Case False
                If OldDay = "" Then
                    MsgBox("The registration information has been tampered with, and the program has been shut down.", MsgBoxStyle.Critical, "Tamper Error!")
                    Application.Exit()
                    Exit Sub
                End If
        End Select

        'If the keys are encrypted, decrypt them.
        If EncryptKeys = True Then
            OldDay = Decrypt(OldDay)
            OldMonth = Decrypt(OldMonth)
            OldYear = Decrypt(OldYear)
        End If

        'Define global variables.
        UsedTrialDays = DiffDate(OldDay, OldMonth, OldYear)

        'Fill the progress bar
        FillBar(DiffDate(OldDay, OldMonth, OldYear), TrialPeriod)

        'Disable the continue button if the trial is over
        If DiffDate(OldDay, OldMonth, OldYear) > TrialPeriod Then
            unregbutton.Enabled = False
            InTrial = False
            oReg = Registry.LocalMachine.OpenSubKey("Software", True)
            oReg = oReg.CreateSubKey(RegSubKeyName)
            oReg.SetValue("Enable", "1")
            oReg.Close()
        End If

        'If the date is earlier than possible, then disable the program.
        If OldMonth = "" Then
        Else
            Dim OldDate As String = OldMonth & "/" & OldDay & "/" & OldYear
            If DateTime.Now.Compare(DateTime.Now, OldDate) < 0 Then
                unregbutton.Enabled = False
                InTrial = False
                oReg = Registry.LocalMachine.OpenSubKey("Software", True)
                oReg = oReg.CreateSubKey(RegSubKeyName)
                oReg.SetValue("Enable", "1")
                oReg.Close()
            End If
        End If


        'If the trial is done then disable the button
        If TrialDone = "1" Then
            unregbutton.Enabled = False
            InTrial = False
            If TrialPeriodDisplay.Visible = True Then
                MsgBox("The system clock has been manually changed, and the application has been locked out to prevent unauthorized access!", MsgBoxStyle.Critical, "Tamper Warning!")
            End If
        End If

        'Hide the about button if you've chosen not to give me credit.
        If SupportMe = False Then
            About.Visible = False
        Else
            About.Visible = True
        End If

        'See if the user is already registered, if so re-process the info and check if the computer is all okay.
        If RegName = "" Then
        Else
            RN = DecryptU(RegName)
            RC = DecryptU(RegCode)
            Dim UserName As String = RegName
            UserName = UserName.Remove(16, (UserName.Length - 16))
            If UserName = DecryptU(RegCode) Then
                If EncryptU(board.GetMotherBoardID.Trim.ToString) = CompID Then
                    InTrial = False
                    FullVersion = True
                    oReg = Registry.LocalMachine.OpenSubKey("Software", True)
                    oReg = oReg.CreateSubKey(RegSubKeyName)
                    oReg.SetValue("Enable", "")
                    oReg.Close()
                End If

            End If
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Enabled = False
        If FullVersion = True Then
            Me.Hide()
            LoadProgramReg(RN, RC)
            Exit Sub
        End If

        If InTrial = True Then
            If SilentStart = True Then
                Me.Hide()
                LoadProgramUnreg(UsedTrialDays)
            End If
        End If
    End Sub

    'Buttons:
    Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
        Application.Exit()
    End Sub
    Private Sub buybutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buybutton.Click
        System.Diagnostics.Process.Start(BuyNowURL)
    End Sub
    Private Sub unlockbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles unlockbutton.Click
        Dim register As New register
        Me.Hide()
        register.ShowDialog()
    End Sub
    Private Sub unregbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles unregbutton.Click
        Me.Hide()
        LoadProgramUnreg(UsedTrialDays)
    End Sub


#End Region
#End Region

End Class
